package perucuy.dao.sqlmap;

import java.util.HashMap;
import java.util.List;

import org.apache.log4j.Logger;
import perucuy.dao.NucleoDAO;
import perucuy.transfers.NucleoTO;
import static perucuy.utils.Funciones.getTipoFecha;
public class SqlMapNucleoDAO extends SqlMapDAO implements NucleoDAO {
    
    /**
     *
     */
    
    private static Logger log = Logger.getLogger(SqlMapNucleoDAO.class);
    
    private static final NucleoDAO dao = new SqlMapNucleoDAO();
    
    private SqlMapNucleoDAO() {
        super(SqlMapDAOFactory.getSqlMap());
        log.debug("dao nucleo instanciado");
    }
    
    public void close() {
        log.debug("cerrando");
    }
    
    public static NucleoDAO getInstance() {
        return dao;
    }
    
    public List listado() {
        return consultaEnLista("getListaNucleo", null);
    }
    
    public void create(NucleoTO nucleo) {
        String id = "" + insert("insertNucleo", nucleo);
        nucleo.setNCodNucleo(Integer.parseInt(id));
    }

    public void actualizar(NucleoTO nucleo){
        update("update-nucleo", nucleo);
    }

    public void actualizarCantidad(NucleoTO nucleo){
        update("updateCantidad-nucleo", nucleo);
    }
    
    public NucleoTO dameNucleo(int id){
        HashMap<String, Integer> hm = new HashMap<String, Integer>();
        hm.put("id", id);
        NucleoTO t = queryForObject("getNucleo", hm);
        return t;
    }
    
    public int eliminarNucleo(int id){
        HashMap hm = new HashMap();
        hm.put("id", id);
        return delete("deleteNucleo", hm);
    }
    
    public List listado(int campo, String valor) {
        HashMap hm = new HashMap();
        hm.put("campo", campo);
        if (campo==2)
            hm.put("valor", getTipoFecha(valor));
        else
            hm.put("valor", valor);
        return consultaEnLista("getListaNucleo", hm);
    }
}
